package com.cyzy.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * AI服务配置类
 */
@Configuration
@ConfigurationProperties(prefix = "ai.service")
public class AiServiceConfig {
    /**
     * AI模型名称
     */
    private String model = "deepseek-chat";
    
    /**
     * API密钥
     */
    private String apiKey;
    
    /**
     * API基础URL
     */
    private String apiBaseUrl = "https://api.deepseek.com";
    
    /**
     * 聊天完成API路径
     */
    private String chatCompletionsPath = "/chat/completions";
    
    /**
     * 连接超时时间(秒)
     */
    private int connectTimeoutSeconds = 60;
    
    /**
     * 读取超时时间(秒)
     */
    private int readTimeoutSeconds = 60;
    
    /**
     * 写入超时时间(秒)
     */
    private int writeTimeoutSeconds = 60;
    
    /**
     * 最大响应令牌数
     */
    private int maxTokens = 2048;
    
    /**
     * 温度参数
     */
    private float temperature = 0.7f;
    
    /**
     * 系统提示词
     */
    private String systemPrompt = "你是智慧农业系统的AI助手，专注于可视化认养农业小程序服务。你可以回答关于农场认养、作物种植、生长周期、农产品质量、线上订购、农场实时监控等问题。你应该帮助用户了解如何通过小程序认养农作物、查看农作物生长状态、参与农场活动以及收获和配送相关信息。如果问题不在你的知识范围内，请回复：'这个问题超出了我的知识范围，我只能回答与智慧农业系统相关的问题。'";
    
    /**
     * 智慧农业相关关键词集合
     */
    private Set<String> agricultureKeywords = new HashSet<>(Arrays.asList(
            // 原有关键词
            "农业", "种植", "作物", "农田", "灌溉", "肥料", "土壤", "病虫害",
            "农产品", "收成", "农机", "智慧农业", "农场", "大棚", "温室",
            "水肥", "农技", "农资", "种子", "农民", "农村", "农产", "农事",
            "耕种", "播种", "收割", "施肥", "除草", "农药", "农具", "农艺",
            "认养", "可视化", "小程序", "线上订购", "农场监控", "生长周期",
            "农产品溯源", "有机种植", "生态农业", "会员服务", "农场体验",
            "农产品配送", "农场直播", "生长状态", "认养证书", "农场活动",
            "农产品礼盒", "季节性农产", "农场地图", "农作物档案", "收获通知",
            "农场动态", "生长日记", "农场社区", "农场问答", "农产品评价",

            // 智慧农业扩展
            "环境监测", "远程控制", "智能传感器", "AI识别", "温湿度采集", "气象数据",
            "智能灌溉", "气候监测", "光照检测", "土壤检测", "数据看板", "自动报警",
            "虫情监测", "智慧种植", "精准农业", "边缘计算", "农业大数据", "智能预警",
            "农业建模", "农业AI", "农业数字化",

            // 可视化扩展
            "可视化平台", "图表展示", "实时数据", "农场数据", "地块分布", "生产看板",
            "数据仪表盘", "状态监控", "作物分布", "可视化地图", "生产分析", "可视化种植",
            "养殖状态", "田块视图", "历史数据", "趋势图", "生长曲线", "可视化追踪",

            // 农场认养扩展
            "认养互动", "家庭农场", "虚拟农场", "认养记录", "产出分享", "认养种类",
            "个性化定制", "认养进度", "农场绑定", "认养互动记录", "认养操作指南",
            "认养排行榜", "认养用户", "认养分红", "农田认领", "认养回报", "可视化认养图",

            // 小程序开发扩展
            "用户登录", "我的认养", "农场展示", "模块化设计", "小程序绑定", "一键订购",
            "订单追踪", "微信支付", "小程序通知", "用户反馈", "农场导航", "农场二维码",
            "一键导航", "消息推送", "用户中心", "权限管理", "签到打卡", "农场相册",
            "视频直播", "活动报名", "小程序入口", "访问统计", "在线客服",

            // 农场体验与运营扩展
            "沉浸式体验", "农业文旅", "农旅融合", "农场打卡", "亲子采摘", "种植日程",
            "农事记录", "会员权益", "认养激励", "农事任务", "实景直播", "节气播报",
            "互动留言", "用户评论", "采摘预约", "农场活动报名"
    ));
    
    /**
     * 关键词匹配阈值
     */
    private int keywordMatchThreshold = 1;
    
    public String getModel() {
        return model;
    }
    
    public void setModel(String model) {
        this.model = model;
    }
    
    public String getApiKey() {
        return apiKey;
    }
    
    public void setApiKey(String apiKey) {
        this.apiKey = apiKey;
    }
    
    public String getApiBaseUrl() {
        return apiBaseUrl;
    }
    
    public void setApiBaseUrl(String apiBaseUrl) {
        this.apiBaseUrl = apiBaseUrl;
    }
    
    public String getChatCompletionsPath() {
        return chatCompletionsPath;
    }
    
    public void setChatCompletionsPath(String chatCompletionsPath) {
        this.chatCompletionsPath = chatCompletionsPath;
    }
    
    public int getConnectTimeoutSeconds() {
        return connectTimeoutSeconds;
    }
    
    public void setConnectTimeoutSeconds(int connectTimeoutSeconds) {
        this.connectTimeoutSeconds = connectTimeoutSeconds;
    }
    
    public int getReadTimeoutSeconds() {
        return readTimeoutSeconds;
    }
    
    public void setReadTimeoutSeconds(int readTimeoutSeconds) {
        this.readTimeoutSeconds = readTimeoutSeconds;
    }
    
    public int getWriteTimeoutSeconds() {
        return writeTimeoutSeconds;
    }
    
    public void setWriteTimeoutSeconds(int writeTimeoutSeconds) {
        this.writeTimeoutSeconds = writeTimeoutSeconds;
    }
    
    public int getMaxTokens() {
        return maxTokens;
    }
    
    public void setMaxTokens(int maxTokens) {
        this.maxTokens = maxTokens;
    }
    
    public float getTemperature() {
        return temperature;
    }
    
    public void setTemperature(float temperature) {
        this.temperature = temperature;
    }
    
    public String getSystemPrompt() {
        return systemPrompt;
    }
    
    public void setSystemPrompt(String systemPrompt) {
        this.systemPrompt = systemPrompt;
    }
    
    public Set<String> getAgricultureKeywords() {
        return agricultureKeywords;
    }
    
    public void setAgricultureKeywords(Set<String> agricultureKeywords) {
        this.agricultureKeywords = agricultureKeywords;
    }
    
    public int getKeywordMatchThreshold() {
        return keywordMatchThreshold;
    }
    
    public void setKeywordMatchThreshold(int keywordMatchThreshold) {
        this.keywordMatchThreshold = keywordMatchThreshold;
    }
    
    /**
     * 获取完整的聊天完成API URL
     */
    public String getChatCompletionsUrl() {
        return apiBaseUrl + chatCompletionsPath;
    }
} 